#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LENGTH_STRING 10


void next_palindrome (char *str, int l)
{
	char *i, *j, *si, *sj, *aux, *end;

	l = strlen(str);
	si = str + (l / 2 - 1);
	sj = si + 1 + (l % 2);
	end = str + l;

	for (i = si, j = sj; j < end; --i, ++j)
	{
		if (*i > *j) {
			*j = *i;
		}
		else if (*i < *j) {
			*i = *j;
			for (aux = i + 1; aux < j; ++aux)
				*aux = '0';
		}
	}
}


int main ()
{
	char from[MAX_LENGTH_STRING], to[MAX_LENGTH_STRING];
	int length, nf, nt;

	scanf ("%[0123456789]\n", from);
	length = strlen(from);
	while (length > 1 || from[0] != '0')
	{
		strcpy (to, from);
		next_palindrome (to, length);
		nf = atoi(from);
		nt = atoi(to);
		fprintf(stderr, "\t%s\n\t%s\n", from, to);
		printf("%d\n", nt - nf);

		scanf ("%[0123456789]\n", from);
		length = strlen(from);
	}
}